package com.example.mindadinner.Activity;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.example.mindadinner.R;
import com.example.mindadinner.manger.ViewPagerManger;
import com.slidingmenu.lib.SlidingMenu;
import com.viewpagerindicator.TitlePageIndicator;

public class MiddleFragment extends LeftBaseFragement {

	private ViewPager mViewPager;
	private TitlePageIndicator titleIndicator;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_middle_fragment);
		inView();
		inData();
	}

	private void inView() {
		mViewPager = (ViewPager) findViewById(R.id.viewpager);
		titleIndicator = (TitlePageIndicator) findViewById(R.id.title_page_indicator);
		titleIndicator.setBackgroundColor(this.getResources().getColor(R.color.tab_background));
		// listView = (ListView) findViewById(R.id.listview);
	}

	private void inData() {
						try {
							mViewPager.setAdapter(ViewPagerManger.getInstance(this).getMiddleViewPagerAdapter());
						} catch (IllegalArgumentException e) {
							e.printStackTrace();
						} catch (IOException e) {
							e.printStackTrace();
						} catch (ClassNotFoundException e) {
							e.printStackTrace();
						} catch (NoSuchMethodException e) {
							e.printStackTrace();
						} catch (InstantiationException e) {
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						} catch (InvocationTargetException e) {
							e.printStackTrace();
						}
		titleIndicator.setViewPager(mViewPager);
		titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageScrollStateChanged(int arg0) {
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageSelected(int position) {
				switch (position) {
				case 0:
					getSlidingMenu().setTouchModeAbove(
							SlidingMenu.TOUCHMODE_FULLSCREEN);
					break;
				default:
					getSlidingMenu().setTouchModeAbove(
							SlidingMenu.TOUCHMODE_MARGIN);
					break;
				}
			}
		});
	}


}
